package com.d3works.apps.sale.service;

import com.d3works.apps.base.service.AddressServiceImpl;
import com.d3works.apps.sale.db.SaleOrder;
import com.d3works.db.JPA;

public class AddressServiceSaleImpl extends AddressServiceImpl {
  static {
    registerCheckUsedFunc(AddressServiceSaleImpl::checkAddressUsedSale);
  }

  private static boolean checkAddressUsedSale(Long addressId) {
    return JPA.all(SaleOrder.class)
            .filter("self.mainInvoicingAddress.id = ?1 OR self.deliveryAddress.id = ?1", addressId)
            .fetchOne()
        != null;
  }
}
